package edu.cuit.avatar.method;

/**
 * 生成各种随机字符
 */
public class RandomCharacter {
    /**
     * 生成随机的大写字母字符
     * @return 大写字母
     */
    public static char randomUpperCase(){
        return randomCharacter('A', 'Z');
    }

    /**
     * 生成随机的小写字母字符
     * @return 小写字母
     */
    public static char randomLowerCase(){
        return randomCharacter('a', 'z');
    }

    /**
     * 生成随机的数字字符
     * @return
     */
    public static char randomDigit(){
        return randomCharacter('0', '9');
    }

    /**
     * 生成任意的随机字符
     * @return 随机字符
     */
    public static char randomCharacter(){
        return randomCharacter('\u0000', '\uffff');
    }

    /**
     * 生成指定范围内的随机字符
     * @param start 起始字符
     * @param end 结束字符
     * @return 范围内随机字符
     */
    public static char randomCharacter(char start, char end){
        return (char)(start + Math.random() * (end - start + 1));
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.print(randomUpperCase() + " ");
        }
        System.out.println();
        for (int i = 0; i < 10; i++) {
            System.out.print(randomLowerCase() + " ");
        }
        System.out.println();
        for (int i = 0; i < 10; i++) {
            System.out.print(randomDigit() + " ");
        }
        System.out.println();
        for (int i = 0; i < 10; i++) {
            System.out.print(randomCharacter() + " ");
        }
        System.out.println();
        for (int i = 0; i < 10; i++) {
            System.out.print(randomCharacter('e', 'x') + " ");
        }
        System.out.println();
    }
}
